<template>
  <div class="person">
    <h2>姓名:{{ name }},{{ nl }}</h2>
    <h2>年龄:{{ age }}</h2>
    <button @click="changeName">修改姓名</button>
    <button @click="changeAge">修改年龄</button>
  </div>
</template>

<script lang="ts" setup name="Person">
  import { reactive, toRefs, toRef } from "vue";

  //数据
  let person = reactive({ name: "弗利萨", age: 18 });

  let { name, age } = toRefs(person); //现在加了toRefs(),name和age就变成了ref的响应式数据
  let nl = toRef(person, "name");
  console.log(nl.value);

  //方法
  function changeName() {
    name.value += "~";
    console.log(name, person.name);
  }
  function changeAge() {
    age.value++;
  }
</script>

<style scoped>
  .person {
    background-color: aqua;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding: 20px;
  }

  button {
    margin-left: 5px;
    margin-right: 5px;
  }
</style>
